function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
layui.use(['form','layer'], function () {

    var $ = layui.$, form = layui.form, layer=layui.layer;

    $(function () {
        // LoginStatus();
    })


    form.on('submit(btnSave)', function (data) {
        var repassword = $('#repassword').val();

        if (repassword != data.field.password) {
            layerMsg("两次密码不一致!");
            return false;
        }

        layer.load(2);
        var id = getUrlParam('id');
        var resetServices = '';
        if(id==1){
            resetServices = services;
        }else{
            resetServices = companyServices;
        }
        $.ajax({
            type: 'post', // 提交方式 get/post
            url: resetServices+"/user/reset/password", // 需要提交的 url
            contentType:"application/json;charset=utf-8",
            xhrFields: {
                withCredentials: true
            }
            ,crossDomain: true
            ,data:JSON.stringify(data.field),
            success: function(res) {
                layer.closeAll('loading');
                if(res.status == '00200'){
                    layerMsg(res.message);
                    setTimeout(function () {
                        logoutCompany();
                    }, 1500)

                }else{
                    layerMsg(res.message)
                }
            },fail:function () {
                layer.closeAll('loading');
            }
        })
        return false;
    });


});




